package com.qiwx.pigeon.presenter;

import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.LoginParam;
import com.qiwx.pigeon.data.vo.EmployBean;
import com.qiwx.pigeon.data.vo.UserBean;
import com.qiwx.pigeon.viewinterface.ILoginView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @description
 * @Author qiwx
 * @Date 2020-05-16 09:52
 **/
public class LoginPresenter extends BasePresenter<ILoginView> {
    public LoginPresenter(WeakReference<ILoginView> from) {
        super(from);
    }

    public LoginPresenter(ILoginView from) {
        super(from);
    }

    public void login(LoginParam params, boolean isShowLoading) {
        ApiManager.getApiServer().login(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<EmployBean>>(isShowLoading) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<EmployBean> response) {
                        getView().onLoginSuccess(response.data);
                    }

                    @Override
                    public void onFailure(String error) {
                        getView().onFailure(error);
                    }
                });
    }
}
